package edu.xlh.travel.controller;

import edu.xlh.travel.dao.ScenicDao;
import edu.xlh.travel.pojo.Scenic;
import edu.xlh.travel.service.ScenicService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/travel")
public class ForeTravelController {
    @Autowired
    private ScenicService scenicService;

    /*
     * search attrs by name
     * */
    @RequestMapping("/search_attrs")
    public String search_attrs(Model model, @RequestParam(value = "start" ,defaultValue = "0")Integer start,
                               @RequestParam(value = "limit" ,defaultValue = "6")Integer limit,
                               @RequestParam String search_key) {
        return scenicService.findAll(model , start , limit , search_key);
    }

    /*
    * search scenic detail by id
    * */
    @RequestMapping("/oneAttr")
    public String oneAttr(Model model , String id) {
        return scenicService.findById(model , id);
    }
}
